package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserBalanceLog;
import com.ruoyi.system.service.IUserBalanceLogService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 用户余额日志 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-06-20
 */
@Controller
@RequestMapping("/system/userBalanceLog")
public class UserBalanceLogController extends BaseController
{
    private String prefix = "system/userBalanceLog";

	@Autowired
	private IUserBalanceLogService userBalanceLogService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:view")
	@GetMapping()
	public String userBalanceLog(UserBalanceLog userBalanceLog,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userBalanceLog.getParams())));
		return prefix + "/userBalanceLog";
	}
	
	/**
	 * 查询用户余额日志列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserBalanceLog userBalanceLog)
	{
		startPage();
        List<UserBalanceLog> list = userBalanceLogService.selectUserBalanceLogList(userBalanceLog);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出用户余额日志列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserBalanceLog userBalanceLog)
    {
    	List<UserBalanceLog> list = userBalanceLogService.selectUserBalanceLogList(userBalanceLog);
        ExcelUtil<UserBalanceLog> util = new ExcelUtil<UserBalanceLog>(UserBalanceLog.class);
        return util.exportExcel(list, "userBalanceLog");
    }
	
	/**
	 * 新增用户余额日志
	 */
	@RequiresPermissions("system:userBalanceLog:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(UserBalanceLog userBalanceLog,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userBalanceLog.getParams())));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户余额日志
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:add")
	@Log(title = "用户余额日志", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserBalanceLog userBalanceLog)
	{		
		return toAjax(userBalanceLogService.insertUserBalanceLog(userBalanceLog));
	}

	/**
	 * 修改用户余额日志
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:edit")
	@GetMapping("/edit/{id}")
	public String edit(UserBalanceLog userBalanceLog,@PathVariable("id") Integer id, ModelMap mmap)
	{
		UserBalanceLog result = userBalanceLogService.selectUserBalanceLogById(id);
		mmap.put("userBalanceLog", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userBalanceLog.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户余额日志
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:edit")
	@Log(title = "用户余额日志", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserBalanceLog userBalanceLog)
	{		
		return toAjax(userBalanceLogService.updateUserBalanceLog(userBalanceLog));
	}
	
	/**
	 * 删除用户余额日志
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userBalanceLog:remove")
	@Log(title = "用户余额日志", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(UserBalanceLog userBalanceLog,String ids)
	{		
		return toAjax(userBalanceLogService.deleteUserBalanceLogByIds(ids));
	}
	
}
